From: Ian Campbell Date: Tue, 7 Sep 2010 18:13:01 +0000 (+0100) Subject: libxc: restore: reset I/O fd to flags to back to state caller passed us X-Git-Tag: archive/raspbian/4.8.0-1+rpi1~1^2~11530 X-Git-Url: https://dgit.raspbian.org/%22http:/www.example.com/cgi/%22https:/%22bookmarks://%22Dat/%22http:/www.example.com/cgi/%22https:/%22bookmarks:/%22Dat?a=commitdiff_plain;h=08aeb139d296e7f9f787cf331f1c6a4824f9061b;p=xen.git libxc: restore: reset I/O fd to flags to back to state caller passed us In particular this causes us to turn O_NONBLOCK back off if we set it. The caller may continue to use the fd for it's own protocol needs and may not be prepared to have it become non-blocking. This probably only effects Remus now after my previous patch to signal the last checkpoint, since a regular migration will no longer set the fd non-blocking. Signed-off-by: Ian Campbell Acked-by: Brendan Cully Signed-off-by: Ian Jackson --- diff --git a/tools/libxc/xc_domain_restore.c b/tools/libxc/xc_domain_restore.c index 6ba5c7580d..be4c5c61e6 100644 --- a/tools/libxc/xc_domain_restore.c +++ b/tools/libxc/xc_domain_restore.c @@ -1094,6 +1094,8 @@ int xc_domain_restore(xc_interface *xch, int io_fd, uint32_t dom, void* vcpup; uint64_t console_pfn = 0; + int orig_io_fd_flags; + static struct restore_ctx _ctx = { .live_p2m = NULL, .p2m = NULL, @@ -1111,6 +1113,11 @@ int xc_domain_restore(xc_interface *xch, int io_fd, uint32_t dom, if ( superpages ) return 1; + if ( (orig_io_fd_flags = fcntl(io_fd, F_GETFL, 0)) < 0 ) { + PERROR("unable to read IO FD flags"); + goto out; + } + if ( read_exact(io_fd, &dinfo->p2m_size, sizeof(unsigned long)) ) { PERROR("read: p2m_size"); @@ -1294,7 +1301,6 @@ int xc_domain_restore(xc_interface *xch, int io_fd, uint32_t dom, // DPRINTF("Received all pages (%d races)\n", nraces); if ( !ctx->completed ) { - int flags = 0; if ( buffer_tail(xch, ctx, &tailbuf, io_fd, max_vcpu_id, vcpumap, ext_vcpucontext) < 0 ) { @@ -1308,11 +1314,7 @@ int xc_domain_restore(xc_interface *xch, int io_fd, uint32_t dom, * nonblocking mode for the remainder. */ if ( !ctx->last_checkpoint ) - { - if ( (flags = fcntl(io_fd, F_GETFL,0)) < 0 ) - flags = 0; - fcntl(io_fd, F_SETFL, flags | O_NONBLOCK); - } + fcntl(io_fd, F_SETFL, orig_io_fd_flags | O_NONBLOCK); } if ( ctx->last_checkpoint ) @@ -1805,8 +1807,10 @@ int xc_domain_restore(xc_interface *xch, int io_fd, uint32_t dom, /* discard cache for save file */ discard_file_cache(xch, io_fd, 1 /*flush*/); + fcntl(io_fd, F_SETFL, orig_io_fd_flags); + DPRINTF("Restore exit with rc=%d\n", rc); - + return rc; } /*